﻿using System;
using System.Linq;
using System.Data;
using System.Web.UI.WebControls;
using ASPNETVN.PORTAL.Components.Helpers;
using ASPNETVN.PORTAL.Components.Security;
using ASPNETVN.PORTAL.Components.UI;
using ASPNETVN.PORTAL.Components.Share;
using CDTM.Modules.ONLINE.Components;
using System.Collections.Generic;

namespace CDTM.Modules.ONLINE.Controls
{
    public partial class Management : AddEditItemControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!PortalSecurity.HasManageAuthorization(this.ModuleID))
            {
                PortalSecurity.AccessDenied();
            }
            if (!IsPostBack)
            {
                LoadData();
            }
        }
        public void LoadData()
        {
            //DataTable dt = CDTM.Modules.ONLINE.Components.Online.SelectAll(this.ModuleID).Tables[0];
            List<Online> _list = Components.Online.SelectCollectionAll(this.ModuleID).Where(x => x.CategoryID == 0).ToList();
            gvOnline.DataSource = _list;
            gvOnline.DataBind();
        }

        protected void gvOnline_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            CDTM.Modules.ONLINE.Components.Online.DeleteOnline(Convert.ToInt32(gvOnline.DataKeys[e.RowIndex].Value));
            LoadData();
        }

        protected void gvOnline_PageIndexChanged(object sender, EventArgs e)
        {
            gvOnline.SelectedIndex = -1;
        }

        protected void gvOnline_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvOnline.PageIndex = e.NewPageIndex;
            LoadData();
        }
    }
}